package com.example.jussi.hotfixdemo;

import android.content.Context;
import android.util.Log;

import com.alipay.euler.andfix.patch.PatchManager;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * Created by admin on 2018/12/9.
 */

public class MyPatchManager extends PatchManager {
    private static final String TAG = "MyPatchManager";
    private static final String DIR = "apatch";
    private File mPatchDir;
    /**
     * @param context context
     */
    public MyPatchManager(Context context) {
        super(context);
        mPatchDir = new File(context.getFilesDir(), DIR);
    }

    @Override
    public void addPatch(String path) throws IOException {
        super.addPatch(path);
        File src = new File(path);
        File dest = new File(mPatchDir, src.getName());
        if (!src.exists()) {
            throw new FileNotFoundException(path);
        }
        if (dest.exists()) {
            boolean deleteResult = dest.delete();
            if (deleteResult)
                Log.e(TAG, "patch [" + dest.getPath() + "] has be delete.");
            else {
                Log.e(TAG, "patch [" + dest.getPath() + "] delete error");
                return;
            }
        }
    }
}
